package main

import (
	"fmt"
	"regexp"
	"strings"
)

func KeyMatch2(key1 string, key2 string) bool {
	key2 = strings.Replace(key2, "/*", "/.*", -1)
	re := regexp.MustCompile(`:[^/]+`)
	key2 = re.ReplaceAllString(key2, "$1[^/]+$2")
	return RegexMatch(key1, "^"+key2+"$")
}

// RegexMatch determines whether key1 matches the pattern of key2 in regular expression.
func RegexMatch(key1 string, key2 string) bool {
	res, err := regexp.MatchString(key2, key1)
	if err != nil {
		panic(err)
	}
	return res
}

func main() {
	key1 := "/rbac/api/v1/xxx/role/adsfasdfasdfasdf"
	key2 := "/rbac/api/v1/:uuid/role/:uuid"
	ret := KeyMatch2(key1, key2)
	fmt.Println(ret)
}
